package m5;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.util.Scanner;


public class Producer {
    public static void main(String[] args) throws Exception {
        //连接
        ConnectionFactory f=new ConnectionFactory();
        f.setHost("192.168.64.140");
        //f.setPort(5672);      //默认端口  可以不写
        f.setUsername("admin");
        f.setPassword("admin");
        Channel c =f.newConnection().createChannel();
        //定义交换机
        c.exchangeDeclare("topic_logs", BuiltinExchangeType.TOPIC);

        //发送消息 需要携带路由器
        while (true){
            System.out.println("输出消息： ");
            String msg=new Scanner(System.in).nextLine();
            System.out.println("输入路由键： ");
            String key=new Scanner(System.in).nextLine();
            //第二个参数是消息上携带的路由键
            c.basicPublish("topic_logs",
                key,null,msg.getBytes() );
        }
    }
}
